<%!
org.jdom.Element createElement(String name, String value){
	org.jdom.Element element = new org.jdom.Element(name);
	if(value != null){
		element.setText(value);
	}
	return element;
}
%><%
whf.framework.ext.service.MenuItemService service = whf.framework.ext.service.MenuItemServiceImp.getMenuItemService();
whf.framework.security.UserContext userContext = whf.framework.web.WebContextHolder.getWebContext(request).getUserContext();
whf.framework.security.entity.User user = userContext.getUser();
whf.framework.security.entity.Dept dept = user == null?null: user.getDept();
java.util.List<whf.framework.ext.entity.MenuItem> menus = whf.framework.util.Utils.newArrayList();
menus.addAll(service.find("t.parent is null and t.deployed=true order by t.sortOrder"));
menus.addAll(service.find("t.parent is not null and t.deployed=true order by t.parent, t.sortOrder"));

org.jdom.Element root = createElement("GlobalInfo", null);
root.addContent(createElement("userid", user == null?"anonymous":user.getUsername()));
root.addContent(createElement("username", user == null?"anonymous":user.getName()));
root.addContent(createElement("dept", dept == null?"":String.valueOf(dept.getId())));

org.jdom.Element navTree = createElement("NavTree", null);
for(whf.framework.ext.entity.MenuItem menu: menus){
	whf.framework.ext.entity.MenuItem parent = menu.getParent();
	if(!whf.framework.util.PermissionUtils.hasPermission(userContext, menu)) continue;
	String pid = parent == null?"1": String.valueOf(parent.getId());
	org.jdom.Element ele = new org.jdom.Element("item");
	ele.setAttribute("pid", pid);
	ele.addContent(createElement("id", String.valueOf(menu.getId())));
	ele.addContent(createElement("name", menu.getName()));
	ele.addContent(createElement("url", menu.getHref()));
	ele.addContent(createElement("extendurl", null));
	navTree.addContent(ele);
}
root.addContent(navTree);
org.jdom.Document document = new org.jdom.Document(root);

response.setContentType("text/xml;charset=UTF-8");
org.jdom.output.XMLOutputter xmlOutputter = new org.jdom.output.XMLOutputter();
xmlOutputter.output(document, response.getOutputStream());
//xmlOutputter.output(document, new java.io.FileOutputStream("e:\\menu.xml"));
%>